package ${properties.daoPkgName};

import java.util.List;
import java.util.ArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.orm.ObjectRetrievalFailureException;
import ${properties.pojoPkgName}.${className} ;

public class ${className}DAO extends HibernateDaoSupport
{

  protected static Logger logger = LoggerFactory.getLogger(${className}.class);

  public void save(${className} ${className?uncap_first})
  {
    getHibernateTemplate().saveOrUpdate(${className?uncap_first});
  }

  public ${className} get${className}(Long id)
  {
    ${className} ${className?uncap_first} = (${className})getHibernateTemplate().get(${className}.class, id);
    if(${className?uncap_first} == null)
    {
      logger.warn("uh oh, ${className} " + id + "' not found...");
      throw new ObjectRetrievalFailureException(${className}.class, id);
    }
  	return ${className?uncap_first};
  }

  @SuppressWarnings("unchecked")
  public List<${className}> get${className}s()
  {
    return getHibernateTemplate().loadAll(${className}.class);
  }
  
  public List<${className}> get${className}s(Long[] ids)
  {
	  List<${className}> list = new ArrayList<${className}>(0);
	  if(ids != null)
	  for(int i=0;i<ids.length;i++)
		  list.add((${className})getHibernateTemplate().load(${className}.class, ids[i]));
	  return list;
  }  

  public void remove(Long id)
  {
    getHibernateTemplate().delete(get${className}(id));
  }
  
  public void merge(${className} ${className?uncap_first})
  {
    getHibernateTemplate().merge(${className?uncap_first});
  }

}